/*
 * @Author: your name
 * @Date: 2020-08-02 14:09:07
 * @LastEditTime: 2020-08-30 20:41:49
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \project\羊绒产业园\源码\src\store\index.js
 */
import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';

//使用vuex
Vue.use(Vuex);
//创建Vuex实例
const store = new Vuex.Store({

    // modules: {
    //     ...
    // },
    // plugins: [createPersistedState({ storage: window.sessionStorage })], // 引入

    // eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJhdWQiOiIiLCJpYXQiOjE1ODkzMDQxODMsIm5iZiI6MTU4OTMwNDE4MywidWlkIjoxLCJyb2xlcyI6IjIifQ.RM2wCPyRsBwyyLNmtiIPZzzx8BHuwKOmuPWeslxz6_o

    state: {
        token: localStorage.getItem("token") || '',
        currentAdress: JSON.parse(localStorage.getItem("currentAdress")) || {},// 地址选择
        openId:'',
        roles: localStorage.getItem("roles") || 'courier',// 地址选择
        userInfo: JSON.parse(localStorage.getItem("userInfo")) || {},
        AnswerInfo: JSON.parse(localStorage.getItem("AnswerInfo")) || {},
        QuestionInfo: JSON.parse(localStorage.getItem("QuestionInfo")) || {},
        crumb: [{
            name: 'index',
            meta: {
                title: '首页',
            },
            path: '/index'
        }]
    },
    mutations: {
     
        EnrollState(state, playload) {
            localStorage.setItem('EnrollInfo', JSON.stringify(playload.parma));
            state.EnrollInfo = playload.parma;
        },
        QuestionState(state, playload) {
            localStorage.setItem('QuestionInfo', JSON.stringify(playload.parma));
            state.QuestionInfo = playload.parma;
        },
        AnswerState(state, playload) {
            localStorage.setItem('AnswerInfo', JSON.stringify(playload.parma));
            state.AnswerInfo = playload.parma;
        },
        ChangeCrumb(state, playload) {
            localStorage.setItem('crumb', JSON.stringify(playload.parma));
            state.crumb = playload.parma;
        },
          //保存用户
       saveUser(state,data){
        localStorage.setItem('userInfo', JSON.stringify(data));

        state.userInfo = JSON.parse(localStorage.getItem("userInfo"))
       },
        //保存openid
        saveOpenId(state,data){
        localStorage.setItem('openId', data);
        state.openId = localStorage.getItem("openId")
        },
        //退出登录
        removeUser(state,data){
            localStorage.clear();
            state.userInfo = data
        },
        //保存token
       saveToken(state,data){
        localStorage.setItem('token', data);

       },
        //保存角色
        saveRoles(state,data){
            localStorage.setItem('roles', data);
    
           },
        
//保存地址
       saveCurrentAdress(state,data){
        localStorage.setItem('currentAdress', JSON.stringify(data));
        console.log('书卷',data)
       }

    }
});

export default store; //导出store